// SPDX-License-Identifier: MIT
pragma solidity ^0.6.11;

contract ${classInfo.className}Contract {

<#assign chainFields = options.chainFields?default([])>
<#if chainFields?size > 0>
    struct Record {
    <#list chainFields as field>
        ${field.solidityType!"string"} ${field.columnName?lower_case};
    </#list>
    }

    mapping(uint256 => Record) private records;

    event RecordSaved(uint256 indexed id<#list chainFields as field>, ${field.solidityType!"string"}<#if field.indexed> indexed</#if> ${field.columnName?lower_case}</#list>);
<#else>
    // TODO: 配置 chainFields 后将生成 struct/mapping/事件定义
    event RecordSaved(uint256 indexed id);
</#if>

    function save${classInfo.className}(uint256 id<#list chainFields as field>, ${field.solidityType!"string"} ${field.columnName?lower_case}</#list>) public {
<#if chainFields?size > 0>
        Record storage record = records[id];
    <#list chainFields as field>
        record.${field.columnName?lower_case} = ${field.columnName?lower_case};
    </#list>
        emit RecordSaved(id<#list chainFields as field>, ${field.columnName?lower_case}</#list>);
<#else>
        // TODO: 填充链上存证逻辑
        emit RecordSaved(id);
</#if>
    }

    function query${classInfo.className}(uint256 id) public view returns (<#if chainFields?size > 0><#list chainFields as field>${field.solidityType!"string"}<#if field_has_next>, </#if></#list><#else>string memory</#if>) {
<#if chainFields?size > 0>
        Record storage record = records[id];
        return (<#list chainFields as field>record.${field.columnName?lower_case}<#if field_has_next>, </#if></#list>);
<#else>
        // TODO: 根据链上存储返回数据
        return "";
</#if>
    }
}
